<?php

namespace App\Http\Controllers;

use App\Models\ClusterReport;
use App\Models\ESCluster;
use App\Models\Predict;
use Illuminate\Http\Request;

class ESClusterController extends Controller
{
    public function index(Request $request)
    {
        $data = ESCluster::with('ESUnit')->requestCriteria($request)->paginate($request->query('limit'));
        return $this->respondSuccess($data);
    }
    public function report(Request $request, ESCluster $esCluster)
    {
        $e_s_cluster_id=$esCluster->id;
        $begin = $request->input('date_begin'); 
        $end = $request->input('date_end'); 
        if($begin){
            $data = ClusterReport::where('e_s_cluster_id', $e_s_cluster_id)->whereBetween('created_at', [$begin, $end])->get();
        }else{
            $data = ClusterReport::where('e_s_cluster_id', $e_s_cluster_id)->limit($request->query('limit', 15))->get();
        }
        return $this->respondSuccess($data);
    }

    public function predict(Request $request, ESCluster $esCluster)
    {
        $e_s_cluster_id=$esCluster->id;
        $begin = $request->input('date_begin'); 
        $end = $request->input('date_end'); 
        if($begin){
            $data = Predict::where('dev_type', 'App\Models\ESCluster')->where('dev_id', $e_s_cluster_id)->whereBetween('created_at', [$begin, $end])->get();
        }else{
            $data = Predict::where('dev_type', 'App\Models\ESCluster')->where('dev_id', $e_s_cluster_id)->limit($request->query('limit', 15))->get();
        }
        return $this->respondSuccess($data);
    }

}
